<?php

/**
 *
 * @author Administrator
 *        
 */
class ServiceController extends CController {
	
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout='//layouts/column2';
	
	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
				'accessControl', // perform access control for CRUD operations
		);
	}
	
	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
				array('allow',  // allow all users to perform 'index' and 'view' actions
						'actions'=>array(),
						'users'=>array('*'),
				),
				array('allow', // allow authenticated user to perform 'create' and 'update' actions
						'actions'=>array('gettags','autosave'),
						'users'=>array('@'),
				),
				array('allow', // allow admin user to perform 'admin' and 'delete' actions
						'actions'=>array('admin','delete'),
						'users'=>array('admin'),
				),
				array('deny',  // deny all users
						'users'=>array('*'),
				),
		);
	}	
	
	public function actionGetTags()
	{
		
		/**
 		 *测试内容： '旅行者1号（Voyager 1）是一艘无人外太阳系太空探测器，重815千克，于1977年9月5日发射。它曾到访过木星及土星，第一次提供了它们卫星的高解析度清晰照片。它是离地球最远和飞行速度最快的人造飞行器，真正意义上飞出了太阳系，首次进入星系空间。旅行者1号与其姊妹船旅行者2号携带的钚电池（核动力电池）将持续到2025年。当电池耗尽之后，他们会停止工作，将继续向着银河系的中心前进。2012年6月14日，美国航空航天局(NASA)宣布，“旅行者”1号探测器在经过长达33年的长途跋涉、飞行约合177亿公里之后，接近太阳系边缘。目前或已飞出太阳系。';
		 */
		
		$content = $_POST['content'];
		
		if(!isset($_POST['content']))
			throw new CHttpException(404,'The requested page does not exist.');

		
		echo UtilTags::getTags($content, 3);
	}
	
	public function actionAutoSave()
	{
		if (Yii::app()->user->isGuest)
			throw new CHttpException(404,'The requested page does not exist.');
		
		$data = $_POST;
		
		$data['from'] = Yii::app()->request->getUrlReferrer();
		
		$string = serialize($data);
		
		UtilAutoSave::saveAsFile($string);
	}
	
	public function actionTest()
	{
		UtilHelper::dump(UtilAutoSave::getAllAchiveInfo());
	}
	
}
?>
 